export default ({ get, post, put }, urls) => {
  const gzlUrl = urls.gzlUrl
  let wsEntity
  return new class {
    // 链接websocket
    linkWsbsocket (phone) {
      if (!('WebSocket' in window)) throw Error('您的浏览器不支持WebSocket')
      if (wsEntity) return wsEntity
      const url = `${gzlUrl}//websocket/${phone}`.replace('http', 'ws')
      wsEntity = new WebSocket(url)
      wsEntity.onclose = function () {
        wsEntity = undefined
      }
      return wsEntity
    }
  }
}
